import 'package:tiktokadult/config/address.dart';
import 'package:tiktokadult/tools_base/debug_log.dart';

/*
ai 视频换脸的数据注释:
modCover 模版图片
modMp4Url 模版视频
picture换脸图片（用户提交的）
cover换脸后封面大图
url换脸后视频地址
*/
class AiRecordModel {
  String? id;
  int? uid;
  String? originPic;
  List<String>? originPics;
  List<String>? newPic;
  List<String>? picture;
  int? coin;
  int? status;
  String? remark;
  String? url;
  String? updateAct;
  String? createdAt;
  String? updatedAt;
  String? vidId;
  String? modPic;
  String? modCover;
  String? modMp4Url;
  String? cover;
  AiRecordModel({
    this.id,
    this.uid,
    this.originPic,
    this.originPics,
    this.newPic,
    this.coin,
    this.status,
    this.remark,
    this.url,
    this.updateAct,
    this.createdAt,
    this.updatedAt,
    this.vidId,
    this.modPic,
  });

  AiRecordModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    uid = json['uid'];
    originPic = json['originPic'];
    originPics = (json['originPics'] as List?)?.map((e) {
      return dynamicToString(e);
    }).toList();
    picture = (json['picture'] as List?)?.map((e) {
      return dynamicToString(e);
    }).toList();
    newPic = (json['newPic'] as List?)?.map((e) {
      return dynamicToString(e);
    }).toList();
    coin = json['coin'];
    status = json['status'];
    remark = json['remark'];
    url = json['url'];
    updateAct = json['updateAct'];
    createdAt = json['createdAt'];
    updatedAt = json['updatedAt'];
    vidId = json['vidId'];
    modPic = json['modPic'];
    modCover = json['modCover'];
    modMp4Url = json['modMp4Url'];
    cover = json['cover'];
  }

  String dynamicToString(dynamic s) {
    if (s == null) return '';
    if (s is String) return s;
    return s.toString();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['uid'] = this.uid;
    data['originPic'] = this.originPic;
    data['originPics'] = this.originPics;
    data['picture'] = this.picture;
    data['newPic'] = this.newPic;
    data['coin'] = this.coin;
    data['status'] = this.status;
    data['remark'] = this.remark;
    data['url'] = this.url;
    data['updateAct'] = this.updateAct;
    data['createdAt'] = this.createdAt;
    data['updatedAt'] = this.updatedAt;

    data['vidId'] = this.vidId;
    return data;
  }
}

extension SourceUrl on AiRecordModel {
  String get realVideoUrl {
    debugLog("videoUrl=${Address.baseApiPath}/vid/h5/m3u8/$url?token=${Address.token}&cdn=${Address.cdnAddress}");
    return "${Address.baseApiPath}/vid/h5/m3u8/$url?token=${Address.token}&cdn=${Address.cdnAddress}";
  }
}
